from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User


class MyUser(models.Model):
    user = models.OneToOneField(User)
    nickname = models.CharField(max_length=16)
    permission = models.IntegerField(default=9)

    def __unicode__(self):
        return self.user.username

class Group(models.Model):
    name = models.CharField(max_length=128)
    author = models.CharField(max_length=128)
    publish_date = models.DateField()
    category = models.CharField(max_length=128)
    info=models.TextField()
    class META:
        ordering = ['name']

    def __unicode__(self):
        return self.name

class Img(models.Model):
    name = models.CharField(max_length=128)
    description = models.TextField()
    img = models.ImageField(upload_to='image/%Y/%m/%d/')
    img_md=models.ImageField(upload_to='image/%Y/%m/%d/')
    group = models.ForeignKey(Group)

    class META:
        ordering = ['name']

    def __unicode__(self):
        return self.name

class Table(models.Model):
    name=models.CharField(max_length=128)
    description = models.TextField()
    file=models.FileField(upload_to='table/%Y/%m/%d/')
    group = models.ForeignKey(Group)
    class META:
        ordering = ['name']

    def __unicode__(self):
        return self.name

class BaseMap(models.Model):
    name=models.CharField(max_length=128)
    file=models.FileField(upload_to='basesvg/')
    scale=models.CharField(max_length=128)
    type=models.CharField(max_length=128)
    projection=models.CharField(max_length=128)
    grade=models.CharField(max_length=128)
    area=models.CharField(max_length=128)
    class META:
        ordering = ['name']

    def __unicode__(self):
        return self.name